package com.tps.controller;

import com.tps.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author charlee
 * @date 2018/4/30
 */
@Api(description = "商品相关接口")
@RestController
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value = "你好", notes = "测试接口，输入昵称，返回一段话")
    @GetMapping("/hello/{username}")
    @PreAuthorize("hasAuthority('read')")
    public String hello(@ApiParam(value = "用户名", name = "username", required = true) @PathVariable String username) {
        return "hello, " + username + "! this is goods-service function";
    }

    @ApiOperation("添加商品")
    @GetMapping("/save")
    @PreAuthorize("hasAuthority('write')")
    public void save() {
        goodsService.save();
    }
}
